Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Query by Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Query_by_Example"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Query_by_Example rootpage-Query_by_Example skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Query by Example</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">

<p><b>Query by Example</b> (<b>QBE</b>) is a <a href="Database" title="Database">database</a> <a href="Query_language" title="Query language">query language</a> for <a href="Relational_database" title="Relational database">relational databases</a>.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>Query by Example was devised by Moshé M. Zloof at <a href="IBM_Research" title="IBM Research">IBM Research</a> during the mid-1970s, in parallel to the development of <a href="SQL" title="SQL">SQL</a>,<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> and influenced by the work on <a href="Relational_database" title="Relational database">relational databases</a> of <a href="Edgar_Codd" class="mw-redirect" title="Edgar Codd">Edgar Codd</a>.<sup id="cite_ref-rdbmsearlyyearsoh20070612_2-0" class="reference"><a href="#cite_note-rdbmsearlyyearsoh20070612-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> It is the first graphical query language, using visual tables where the user would enter commands, example elements and conditions. Many graphical front-ends for databases use the ideas from QBE today. Originally limited only for the purpose of <a href="Data_retrieval" title="Data retrieval">retrieving data</a>, QBE was later extended to allow other operations, such as inserts, deletes and updates, as well as creation of temporary tables.
</p><p>The motivation behind QBE is that a <a href="Parser" class="mw-redirect" title="Parser">parser</a> can convert the user's actions into statements expressed in a database manipulation language, such as <a href="SQL" title="SQL">SQL</a>. Behind the scenes, it is this statement that is actually executed. A suitably comprehensive front-end can minimize the burden on the user to remember the finer details of SQL, and it is easier and more productive for end-users (and even programmers) to select tables and columns by selecting them rather than typing in their names.
</p><p>In the context of <a href="Information_retrieval" title="Information retrieval">information retrieval</a>, QBE has a somewhat different meaning. The user can submit a document, or several documents, and ask for "similar" documents to be retrieved from a document database [see search by multiple examples<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>]. Similarity search is based comparing document vectors (see <a href="Vector_Space_Model" class="mw-redirect" title="Vector Space Model">Vector Space Model</a>).
</p><p>QBE represents seminal work in <a href="End-user_development" title="End-user development">end-user development</a>, frequently cited in research papers as an early example of this topic.
</p><p>Currently, QBE is supported in several relational database front ends, notably <a href="Microsoft_Access" title="Microsoft Access">Microsoft Access</a>, which implements "Visual Query by Example", as well as Microsoft SQL Server Enterprise Manager. It is also implemented in several <a href="Object_database" title="Object database">object-oriented databases</a> (e.g. in <a href="Db4o" title="Db4o">db4o</a><sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>).
</p><p>QBE is based on the logical formalism called tableau query, although QBE adds some extensions to that, much like SQL is based on the <a href="Relational_algebra" title="Relational algebra">relational algebra</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<p>An example using the <a href="Suppliers_and_Parts_database" title="Suppliers and Parts database">Suppliers and Parts database</a> is given here to illustrate how QBE works.
</p>
<table class="wikitable">
<caption>Simple QBE example
</caption>
<tbody><tr>
<th>S</th>
<th>S#</th>
<th>SNAME</th>
<th>OWNER</th>
<th>SCITY
</th></tr>
<tr>
<td></td>
<td>P.<u>SX</u></td>
<td></td>
<td>J. DOE</td>
<td>ROME
</td></tr></tbody></table>
<div class="mw-heading mw-heading2"><h2 id="As_a_general_technique">As a general technique</h2></div>
<p>The term also refers to a general technique influenced by Zloof's work whereby only items with search values are used to "filter" the results. It provides a way for a software user to perform queries without having to know a query language (such as <a href="SQL" title="SQL">SQL</a>). The software can automatically generate the queries for the user (usually behind the scenes). Here are two examples based on a Contacts table with the following text (character) columns: Name, Address, City, State, and Zipcode:
</p>
<pre>Contacts Query Form - Example <b>A</b>:
.....Name: Bob
..Address:
.....City:
....State: TX
..Zipcode:
</pre>
<p>Resulting <a href="SQL" title="SQL">SQL</a>:
</p>
<div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">Contacts</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">Name</span><span class="o">=</span><span class="s1">'Bob'</span><span class="w"> </span><span class="k">AND</span><span class="w"> </span><span class="k">State</span><span class="o">=</span><span class="s1">'TX'</span><span class="p">;</span>
</pre></div>
<p>Note how blank items do not generate <a href="SQL" title="SQL">SQL</a> terms. Since "Address" is blank, there is no clause generated for it.
</p>
<pre>Contacts Query Form - Example <b>B</b>:
.....Name:
..Address:
.....City: Sampleton
....State:
..Zipcode: 12345
</pre>
<p>Resulting <a href="SQL" title="SQL">SQL</a>:
</p>
<div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">Contacts</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">City</span><span class="o">=</span><span class="s1">'Sampleton'</span><span class="w"> </span><span class="k">AND</span><span class="w"> </span><span class="n">Zipcode</span><span class="o">=</span><span class="s1">'12345'</span><span class="p">;</span>
</pre></div>
<p>More advanced versions of QBE have other comparison operator options, often via a pull-down menu, such as "Contains", "Not Contains", "Starts With", "Greater-Than", and so forth.
</p><p>Another approach to text comparisons is to allow one or more <a href="Wildcard_character" title="Wildcard character">wildcard character</a> characters. For example, if an asterisk is designated as a wildcard character in a particular system, then searching for last names using "Rob<b>*</b>" would return (match) last names such as "Rob", "Robert", "Robertson", "Roberto", etc.
</p>
<pre>Contacts Query Form - Example <b>C</b>:
.....Name: Rob*
..Address:
.....City:
....State:
..Zipcode:
</pre>
<p>Resulting <a href="SQL" title="SQL">SQL</a>:
</p>
<div class="mw-highlight mw-highlight-lang-sql mw-content-ltr" dir="ltr"><pre><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">Contacts</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">Name</span><span class="w"> </span><span class="k">LIKE</span><span class="w"> </span><span class="s1">'Rob%'</span>
</pre></div>
<p>In standard SQL, the percent sign functions like a wildcard in a LIKE clause. In this case, the query-by-examplme form processing software would translate the asterisk to a percent sign. (An asterisk is a more common wildcard convention outside of SQL, so here the form is attempting to be more <a href="User_friendly" class="mw-redirect" title="User friendly">user friendly</a>.)
</p><p>WARNING: Query-by-example software should be careful to avoid <a href="SQL_injection" title="SQL injection">SQL injection</a>. Otherwise, devious users may penetrate further into the database than intended by builders of the query forms.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="CRUD" class="mw-redirect" title="CRUD">CRUD</a></li>
<li><a href="Microsoft_Query_by_Example" class="mw-redirect" title="Microsoft Query by Example">Microsoft Query by Example</a></li>
<li><a href="GraphQL" title="GraphQL">GraphQL</a> a QBE for JSON front-ends.</li>
<li><a href="QBIC" class="mw-redirect" title="QBIC">QBIC</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFZloof1977" class="citation journal cs1">Zloof, M.M. (1977). "Query-by-Example: A data base language". <i>IBM Systems Journal</i>. <b>16</b> (4): <span class="nowrap">324–</span>343. <a href="CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&nbsp;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.86.3485">10.1.1.86.3485</a></span>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1147%2Fsj.164.0324">10.1147/sj.164.0324</a>.</cite></span>
</li>
<li id="cite_note-rdbmsearlyyearsoh20070612-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-rdbmsearlyyearsoh20070612_2-0">^</a></b></span> <span class="reference-text"><cite class="citation interview cs1"><a rel="nofollow" class="external text" href="https://archive.computerhistory.org/resources/access/text/2013/05/102702562-05-01-acc.pdf">"RDBMS Plenary 1: Early Years"</a> <span class="cs1-format">(PDF)</span> (Interview). Interviewed by Burton Grad. Computer History Museum. 2007-06-12. pp.&nbsp;<span class="nowrap">23–</span>24<span class="reference-accessdate">. Retrieved <span class="nowrap">2025-05-30</span></span>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite id="CITEREFZhuWu2014" class="citation book cs1">Zhu, Mingzhu; Wu, Yi-Fang Brook (2014-02-24). "Search by multiple examples". <i>Proceedings of the 7th ACM international conference on Web search and data mining</i>. ACM. pp.&nbsp;<span class="nowrap">667–</span>672. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F2556195.2556206">10.1145/2556195.2556206</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>9781450323512</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:8397529">8397529</a>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation cs2">"QBE", <a rel="nofollow" class="external text" href="http://www.ibm.com/developerworks/java/library/j-db4o2.html"><i>db4o</i></a>, Developer works Java library, IBM, 27 March 2007</cite></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="Sources">Sources</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239549316">
/* start https://en.wikipedia.org/ */


.mw-parser-output .refbegin{margin-bottom:0.5em}.mw-parser-output .refbegin-hanging-indents>ul{margin-left:0}.mw-parser-output .refbegin-hanging-indents>ul>li{margin-left:0;padding-left:3.2em;text-indent:-3.2em}.mw-parser-output .refbegin-hanging-indents ul,.mw-parser-output .refbegin-hanging-indents ul li{list-style:none}@media(max-width:720px){.mw-parser-output .refbegin-hanging-indents>ul>li{padding-left:1.6em;text-indent:-1.6em}}.mw-parser-output .refbegin-columns{margin-top:0.3em}.mw-parser-output .refbegin-columns ul{margin-top:0}.mw-parser-output .refbegin-columns li{page-break-inside:avoid;break-inside:avoid-column}@media screen{.mw-parser-output .refbegin{font-size:90%}}


/* end https://en.wikipedia.org/ */
</style><div class="refbegin" style="">
<ul><li><cite id="CITEREFZloof1975" class="citation cs2">Zloof, Moshé M. (May 1975), "Query by Example", <i>National Computer Conference</i>, AFIPS Conference Proceedings, vol.&nbsp;44, Anaheim, California: AFIPS Press, pp.&nbsp;<span class="nowrap">431–</span>8, <a href="ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&nbsp;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0095-6880">0095-6880</a></cite>.</li>
<li><cite id="CITEREFRamakrishnanGehrke" class="citation cs2"><a href="Raghu_Ramakrishnan" title="Raghu Ramakrishnan">Ramakrishnan, Raghu</a>; <a href="Johannes_Gehrke" title="Johannes Gehrke">Gehrke, Johannes</a>, <a rel="nofollow" class="external text" href="http://www.cs.wisc.edu/~dbbook/openAccess/thirdEdition/qbe.pdf">"6. QBE"</a> <span class="cs1-format">(PDF)</span>, <i>Database Management Systems</i> (3rd&nbsp;ed.), Wisc</cite>.</li>
<li><cite id="CITEREFDate2004" class="citation cs2">Date, Christopher ‘Chris’ J. (2004), "8. Relational Calculus", <i>An Introduction to Database Systems</i>, Addison-Wesley Pearson, pp.&nbsp;<span class="nowrap">242–</span>7, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-321-18956-1</bdi></cite>.</li>
<li><cite class="citation cs2"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20060614102510/http://searchoracle.techtarget.com/sDefinition/0,,sid41_gci214554,00.html"><i>Oracle Definitions</i></a>, Tech target, archived from <a rel="nofollow" class="external text" href="http://searchoracle.techtarget.com/sDefinition/0,,sid41_gci214554,00.html">the original</a> on 2006-06-14<span class="reference-accessdate">, retrieved <span class="nowrap">2006-06-25</span></span></cite>.</li>
<li><cite id="CITEREFZaiane1998" class="citation cs2">Zaiane, O. (1998), <a rel="nofollow" class="external text" href="http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter5/node2.html">"5. Query-by-Example (QBE)"</a>, <i>CC 354 notes</i>, Canada: SFI</cite>.</li></ul>
</div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html#querycriteria-examples">"Query by Example in Java using Hibernate"</a>. JBoss.</cite></li>
<li><cite id="CITEREFSoyluGieseJimenez-RuizVega-Gorgojo2015" class="citation journal cs1">Soylu, Ahmet; Giese, Martin; Jimenez-Ruiz, Ernesto; Vega-Gorgojo, Guillermo; Horrocks, Ian (2015). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20221205202950/http://www.ahmetsoylu.com/wp-content/uploads/soylu_UAIS_2016.pdf">"Experiencing OptiqueVQS: a multi-paradigm and ontology-based visual query system for end users"</a> <span class="cs1-format">(PDF)</span>. <i>Universal Access in the Information Society</i>. <b>15</b>: <span class="nowrap">129–</span>152. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2Fs10209-015-0404-5">10.1007/s10209-015-0404-5</a>. <a href="Hdl_(identifier)" class="mw-redirect" title="Hdl (identifier)">hdl</a>:<a rel="nofollow" class="external text" href="https://hdl.handle.net/11250%2F2388519">11250/2388519</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:254169347">254169347</a>. Archived from <a rel="nofollow" class="external text" href="http://www.ahmetsoylu.com/wp-content/uploads/soylu_UAIS_2016.pdf">the original</a> <span class="cs1-format">(PDF)</span> on 2022-12-05<span class="reference-accessdate">. Retrieved <span class="nowrap">2021-11-12</span></span>. <q>Visual Query System (VQS)</q></cite></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-29" href="https://en.wikipedia.org/wiki/?title=Query_by_Example&amp;oldid=1303158230">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>